﻿using Infrastructure.ViewModel;
using UltimateNavigationFramework.UriNavigation;
using Microsoft.Practices.Prism.Regions;

namespace Ultimate.Home.ViewModels
{
    public class HomeSubViewModel : ViewModelBase, IPageTitle, INavigationAware
    {
        // Because RegionName needs to be unique across application, and we have a unique instance per id, so we append the id to the RegionName
        private string _regionName;
        public string RegionName
        {
            get
            {
                return _regionName;
            }
            set
            {
                _regionName = value;
                this.NotifyPropertyChanged(() => this.RegionName);
            }
        }

        private string _id;
        public string Id 
        {
            get
            {
                return _id;
            }
            set
            {
                _id = value;
                this.NotifyPropertyChanged(() => this.Id);
            }
        }

        #region IPageTitle Implementation
        public string PageTitle
        {
            get { return "Home Sub View"; }
        } 
        #endregion

        bool INavigationAware.IsNavigationTarget(NavigationContext navigationContext)
        {
            // Will load each instance based on the unique id
            return this.Id == navigationContext.Parameters["id"];     
        }

        void INavigationAware.OnNavigatedFrom(NavigationContext navigationContext)
        {
            
        }

        void INavigationAware.OnNavigatedTo(NavigationContext navigationContext)
        {
            var id = navigationContext.Parameters["id"];
            this.Id = id;
            this.RegionName = "SubRegion" + Id;
        }
    }
}
